﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// Implémentation de l'effet BandedSwirl
    /// </summary>
    public class BandedSwirlEffect : ShaderEffect
    {
        #region Propriétés de dépendances

        public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(BandedSwirlEffect), new UIPropertyMetadata(new Point(0.5, 0.5), ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty SwirlStrengthProperty = DependencyProperty.Register("SwirlStrength", typeof(double), typeof(BandedSwirlEffect), new UIPropertyMetadata(0.5, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty DistanceThresholdProperty = DependencyProperty.Register("DistanceThreshold", typeof(double), typeof(BandedSwirlEffect), new UIPropertyMetadata(0.2, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BandedSwirlEffect), 0);

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la valeur du centre
        /// </summary>
        public Point Center
        {
            get
            {
                return ((Point)this.GetValue(BandedSwirlEffect.CenterProperty));
            }
            set
            {
                this.SetValue(BandedSwirlEffect.CenterProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne le seuil de la dDistance
        /// </summary>
        public double DistanceThreshold
        {
            get
            {
                return ((double)this.GetValue(BandedSwirlEffect.DistanceThresholdProperty));
            }
            set
            {
                this.SetValue(BandedSwirlEffect.DistanceThresholdProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la texture du shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(BandedSwirlEffect.InputProperty));
            }
            set
            {
                this.SetValue(BandedSwirlEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la force du tourbillon
        /// </summary>
        public double SwirlStrength
        {
            get
            {
                return ((double)this.GetValue(BandedSwirlEffect.SwirlStrengthProperty));
            }
            set
            {
                this.SetValue(BandedSwirlEffect.SwirlStrengthProperty, value);
            }
        }

        #endregion

        #region Variables d'instances

        private static readonly PixelShader _PixelShader;

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique de la classe
        /// </summary>
        static BandedSwirlEffect()
        {
            BandedSwirlEffect._PixelShader = new PixelShader();
            BandedSwirlEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/BandedSwirl.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public BandedSwirlEffect()
        {
            this.PixelShader = _PixelShader;

            this.UpdateShaderValue(BandedSwirlEffect.CenterProperty);
            this.UpdateShaderValue(BandedSwirlEffect.SwirlStrengthProperty);
            this.UpdateShaderValue(BandedSwirlEffect.DistanceThresholdProperty);
            this.UpdateShaderValue(BandedSwirlEffect.InputProperty);
        }

        #endregion
    }
}